package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SentimentAnalysis;
import com.ruoyi.system.service.ISentimentAnalysisService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 情感分析结果，存储帖子或评论的情感分析数据Controller
 * 
 * @author ruoyi
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/system/analysis")
public class SentimentAnalysisController extends BaseController
{
    @Autowired
    private ISentimentAnalysisService sentimentAnalysisService;

    /**
     * 查询情感分析结果，存储帖子或评论的情感分析数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:analysis:list')")
    @GetMapping("/list")
    public TableDataInfo list(SentimentAnalysis sentimentAnalysis)
    {
        startPage();
        List<SentimentAnalysis> list = sentimentAnalysisService.selectSentimentAnalysisList(sentimentAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出情感分析结果，存储帖子或评论的情感分析数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:analysis:export')")
    @Log(title = "情感分析结果，存储帖子或评论的情感分析数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SentimentAnalysis sentimentAnalysis)
    {
        List<SentimentAnalysis> list = sentimentAnalysisService.selectSentimentAnalysisList(sentimentAnalysis);
        ExcelUtil<SentimentAnalysis> util = new ExcelUtil<SentimentAnalysis>(SentimentAnalysis.class);
        util.exportExcel(response, list, "情感分析结果，存储帖子或评论的情感分析数据数据");
    }

    /**
     * 获取情感分析结果，存储帖子或评论的情感分析数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:analysis:query')")
    @GetMapping(value = "/{analysisId}")
    public AjaxResult getInfo(@PathVariable("analysisId") Long analysisId)
    {
        return success(sentimentAnalysisService.selectSentimentAnalysisByAnalysisId(analysisId));
    }

    /**
     * 新增情感分析结果，存储帖子或评论的情感分析数据
     */
    @PreAuthorize("@ss.hasPermi('system:analysis:add')")
    @Log(title = "情感分析结果，存储帖子或评论的情感分析数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SentimentAnalysis sentimentAnalysis)
    {
        return toAjax(sentimentAnalysisService.insertSentimentAnalysis(sentimentAnalysis));
    }

    /**
     * 修改情感分析结果，存储帖子或评论的情感分析数据
     */
    @PreAuthorize("@ss.hasPermi('system:analysis:edit')")
    @Log(title = "情感分析结果，存储帖子或评论的情感分析数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SentimentAnalysis sentimentAnalysis)
    {
        return toAjax(sentimentAnalysisService.updateSentimentAnalysis(sentimentAnalysis));
    }

    /**
     * 删除情感分析结果，存储帖子或评论的情感分析数据
     */
    @PreAuthorize("@ss.hasPermi('system:analysis:remove')")
    @Log(title = "情感分析结果，存储帖子或评论的情感分析数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{analysisIds}")
    public AjaxResult remove(@PathVariable Long[] analysisIds)
    {
        return toAjax(sentimentAnalysisService.deleteSentimentAnalysisByAnalysisIds(analysisIds));
    }
}
